#!/bin/bash

export ROS_LOG_DIR=/home/reiko/codespace/ros2code/carto_humble/log
source /home/reiko/codespace/ros2code/carto_humble/cartographer_ros/install/setup.bash

#mapfile=$(dirname $(pwd))/assets/b0-2014-07-21-12-49-192d
mapfile=$(pwd)/assets/b0-2014-07-21-12-49-192d
#finish trajectory
ros2 service call /finish_trajectory cartographer_ros_msgs/srv/FinishTrajectory "trajectory_id: 0"
sleep 3
echo "save file $mapfile.pbstream"
#save pbsream
ros2 service call /write_state cartographer_ros_msgs/srv/WriteState "{filename: '$mapfile.pbstream'}"
sleep 5
#pbstream to map
ros2 run cartographer_ros cartographer_pbstream_to_ros_map \
-pbstream_filename=$mapfile.pbstream \
-map_filestem=$mapfile